/**
 * 数据统计管理初始化
 */
var Count = {
    id: "CountTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Count.formParams = function() {
    var queryData = {};
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();

    return queryData;
}
Count.getBannerNum = function(num,num1) {
	if(num1==1){
		var div2 = $('#bannerIds');
		for(var i = 1;i<=num;i++){
	    	var h4 = document.createElement('h4');
	    	h4.id='id'+i;
	    	h4.innerHTML='banner'+i+'点击量：';
	    	var span = document.createElement('span');
	    	span.className = 'label  label-danger';
	    	span.id='banner'+i;
	    	h4.appendChild(span)
	    	div2.append(h4);
	    	$('#id'+i).css({'float':'left','margin':'20px 20px'}); 
	    	$('#banner'+i).html(0);
	    	}
		}
	if(num1==2){
		for(var i = 1;i<=num;i++){
	    	$('#banner'+i).html(0);
	    }
	}
}

Count.getLoginBannerNum = function(num,num1) {
    if(num1==1){
        var div2 = $('#userBannerIds');
        for(var i = 1;i<=num;i++){
            var h4 = document.createElement('h4');
            h4.id='userid'+i;
            h4.innerHTML='登录用户banner'+i+'点击量：';
            var span = document.createElement('span');
            span.className = 'label  label-danger';
            span.id='userbanner'+i;
            h4.appendChild(span)
            div2.append(h4);
            $('#userid'+i).css({'float':'left','margin':'20px 20px'});
            $('#userbanner'+i).html(0);
        }
    }
    if(num1==2){
        for(var i = 1;i<=num;i++){
            $('#userbanner'+i).html(0);
        }
    }
}


Count.search = function () {
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/dataCount/listcount/',
        data:Count.formParams(),
        dataType: "json",
        success: function(data){
        	var num= data['bannerNum'];
        	Count.getBannerNum(num,2);
        	$("#homeCount").html(0);
            $("#startPlatform1").html(0);
            $("#startPlatform2").html(0);
            $("#startPlatform3").html(0);
            $("#startPlatform0").html(0);
            $("#CardPageId1").html(0);
            $("#button1").html(0);
            $("#button2").html(0);
            $("#button3").html(0);
            $("#button4").html(0);
            $("#button5").html(0);
            for(var map in data){
            	$("#"+map).html(data[map]);
            }
            getLoginBannerData();
        },
    });


};

function getLoginBannerData(){
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/dataCount/loginListcount/',
        data:Count.formParams(),
        dataType: "json",
        success: function(data){
            var num= data['loginBannerNum'];
            Count.getLoginBannerNum(num,2);
            $("#userhomeCount").html(0);
            $("#userstartPlatform1").html(0);
            $("#userstartPlatform2").html(0);
            $("#userstartPlatform3").html(0);
            $("#userstartPlatform0").html(0);
            $("#userCardPageId1").html(0);
            $("#userbutton1").html(0);
            $("#userbutton2").html(0);
            $("#userbutton3").html(0);
            $("#userbutton4").html(0);
            $("#userbutton5").html(0);
            for(var map in data){
                $("#"+map).html(data[map]);
            }
        }
    });
}

function refreshCount(){
	$("#refreshData").href=Feng.ctxPath + "/dataCount";
}

var parseParam = function(param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function(i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};

//设置时间规范函数format
Date.prototype.format = function(format) {
    var date = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
    }
    return format;
}


$(function () {
    //设置系统查询的默认时间
    var t=new Date();
    t.setTime(t.getTime());
    document.getElementById("beginTime").value = t.format("yyyy-MM-dd");
    document.getElementById("endTime").value = t.format("yyyy-MM-dd");


    $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/dataCount/listcount/',
        data:Count.formParams(),
        dataType: "json",
        success: function(data){
        	var num= data['bannerNum'];
        	Count.getBannerNum(num,1);
        	Count.getLoginBannerNum(num,1);
        	$("#homeCount").html(0);
            $("#startPlatform1").html(0);
            $("#startPlatform2").html(0);
            $("#startPlatform3").html(0);
            $("#startPlatform0").html(0);
            $("#CardPageId1").html(0);
            $("#button1").html(0);
            $("#button2").html(0);
            $("#button3").html(0);
            $("#button4").html(0);
            $("#button5").html(0);
            for(var map in data){
            	$("#"+map).html(data[map]);
            }
            getLoginBannerData();
        },
    });

});

